Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: openapi query namespace support not fill item #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

youngzil
Copy link

@youngzil youngzil commented Oct 8, 2024

What's the purpose of this PR

XXXXX

Which issue(s) this PR fixes:

Fixes apolloconfig/apollo/issues/5243

Brief changelog

XXXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

Summary by CodeRabbit

  • New Features

    • Enhanced API methods for retrieving namespaces and specific namespace details, allowing users to specify the level of detail for item retrieval.
  • Bug Fixes

    • Deprecated older method signatures to streamline usage and ensure consistency with new parameters.
  • Tests

    • Updated test cases to align with the revised method signatures for improved accuracy in testing functionality.

Copy link
Contributor

coderabbitai bot commented Oct 8, 2024

Walkthrough

The changes in this pull request involve modifications to the NamespaceOpenApiService interface, the ApolloOpenApiClient class, and the NamespaceOpenApiService class. Specifically, the getNamespace and getNamespaces methods have been updated to include a new boolean parameter, fillItemDetail, which allows clients to specify whether to retrieve detailed item information. Additionally, deprecated versions of these methods have been introduced, guiding users to the new method signatures.

Changes

File Change Summary
.../NamespaceOpenApiService.java Updated method signatures for getNamespace and getNamespaces to include boolean fillItemDetail.
.../ApolloOpenApiClient.java Deprecated methods for getNamespace and getNamespaces; added overloaded methods with fillItemDetail.
.../NamespaceOpenApiService.java Updated public method signatures for getNamespace and getNamespaces to include boolean fillItemDetail.
.../NamespaceOpenApiServiceTest.java Updated test methods to reflect new signatures with boolean fillItemDetail.

Assessment against linked issues

Objective Addressed Explanation
Add parameter to control item detail retrieval for getNamespaces (5243)
Add parameter to control item detail retrieval for getNamespace (5243)

🐇 In the meadow, I hop and play,
New methods here, hip-hip-hooray!
With a boolean flag, oh what a treat,
Fetching details, oh so neat!
For namespaces, we now can choose,
To fill with items, or just peruse! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (12)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/NamespaceOpenApiService.java (3)

29-29: Approve change with suggestions for improvement

The addition of the fillItemDetail parameter aligns with the PR objectives and provides the desired functionality to optionally retrieve item details. However, there are a couple of improvements that could be made:

  1. Add documentation for the new fillItemDetail parameter to clarify its purpose and usage.
  2. Consider adding a deprecated version of the old method signature to maintain backwards compatibility for existing clients.

Here's a suggested implementation with these improvements:

/**
 * Get namespace information.
 *
 * @param appId The application ID
 * @param env The environment
 * @param clusterName The cluster name
 * @param namespaceName The namespace name
 * @param fillItemDetail Whether to fill item details in the response
 * @return The namespace information
 */
OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName, boolean fillItemDetail);

/**
 * @deprecated Use {@link #getNamespace(String, String, String, String, boolean)} instead.
 */
@Deprecated
default OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
    return getNamespace(appId, env, clusterName, namespaceName, true);
}

This approach provides clear documentation and maintains backwards compatibility.


31-31: Approve change with suggestions for improvement

The addition of the fillItemDetail parameter to the getNamespaces method aligns with the PR objectives and provides the desired functionality to optionally retrieve item details for multiple namespaces. However, similar to the getNamespace method, there are a couple of improvements that could be made:

  1. Add documentation for the new fillItemDetail parameter to clarify its purpose and usage.
  2. Consider adding a deprecated version of the old method signature to maintain backwards compatibility for existing clients.

Here's a suggested implementation with these improvements:

/**
 * Get multiple namespaces information.
 *
 * @param appId The application ID
 * @param env The environment
 * @param clusterName The cluster name
 * @param fillItemDetail Whether to fill item details in the response
 * @return List of namespace information
 */
List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName, boolean fillItemDetail);

/**
 * @deprecated Use {@link #getNamespaces(String, String, String, boolean)} instead.
 */
@Deprecated
default List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
    return getNamespaces(appId, env, clusterName, true);
}

This approach provides clear documentation and maintains backwards compatibility.


Line range hint 1-38: Overall feedback on changes

The modifications to the NamespaceOpenApiService interface successfully implement the desired functionality to optionally retrieve item details when fetching namespace information. This aligns well with the PR objectives and addresses the issue described in #5243.

However, to ensure a smooth transition and maintain API usability, consider the following recommendations:

  1. Add clear documentation for the new fillItemDetail parameter in both getNamespace and getNamespaces methods.
  2. Implement deprecated versions of the old method signatures to maintain backwards compatibility.
  3. Update the class-level documentation to mention this new functionality.

These changes will significantly improve the API's usability and ensure a smoother transition for existing clients.

As this change affects a public API, consider updating the API documentation and providing migration guides for users upgrading to this new version. Additionally, it might be beneficial to add examples of how to use these new method signatures in the Apollo documentation.

apollo-openapi/src/test/java/com/ctrip/framework/apollo/openapi/client/service/NamespaceOpenApiServiceTest.java (2)

61-61: Consider adding a test case for fillItemDetail=false.

The test has been updated to use the new method signature with fillItemDetail=true, which is good. However, to ensure comprehensive test coverage, it would be beneficial to add another test case that checks the behavior when fillItemDetail is set to false.

Would you like me to provide an example of how to implement this additional test case?


86-86: Consider adding a test case for fillItemDetail=false.

The test has been updated to use the new method signature with fillItemDetail=true, which is good. However, to ensure comprehensive test coverage, it would be beneficial to add another test case that checks the behavior when fillItemDetail is set to false for the getNamespaces method.

Would you like me to provide an example of how to implement this additional test case?

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/NamespaceOpenApiService.java (3)

Line range hint 44-62: LGTM! Consider adding a deprecated method for backwards compatibility.

The changes to getNamespace method look good and align with the PR objectives. The new fillItemDetail parameter is correctly added and used in the OpenApiPathBuilder.

To ensure better backwards compatibility, consider adding a deprecated version of the method:

@Deprecated
@Override
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
    return getNamespace(appId, env, clusterName, namespaceName, true);
}

This will allow existing code to continue working while encouraging migration to the new method signature.


Line range hint 73-88: LGTM! Consider adding a deprecated method for backwards compatibility.

The changes to getNamespaces method look good and align with the PR objectives. The new fillItemDetail parameter is correctly added and used in the OpenApiPathBuilder.

To ensure better backwards compatibility, consider adding a deprecated version of the method:

@Deprecated
@Override
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
    return getNamespaces(appId, env, clusterName, true);
}

This will allow existing code to continue working while encouraging migration to the new method signature.


Incomplete Updates in Related Classes

The NamespaceOpenApiService interface has been successfully updated with the new fillItemDetail parameter. However, the ApolloOpenApiClient class still contains deprecated method calls to getNamespace and getNamespaces that need to be updated to utilize the new parameters.

Please address the following:

  • Replace deprecated getNamespace and getNamespaces calls in the ApolloOpenApiClient class with the updated method signatures that include the fillItemDetail parameter.
  • Update all existing calls across the codebase to use the new methods to ensure consistency and leverage the improved functionality.
  • Consider removing or properly documenting deprecated methods to prevent future confusion and maintain codebase cleanliness.
🔗 Analysis chain

Line range hint 1-145: Overall changes look good. Don't forget to update related classes.

The modifications to getNamespace and getNamespaces methods are well-implemented and align with the PR objectives. The new fillItemDetail parameter allows clients to control whether to retrieve detailed item information, which should improve efficiency as intended.

To ensure consistency across the codebase, please make sure to:

  1. Update the NamespaceOpenApiService interface with the new method signatures.
  2. Modify the ApolloOpenApiClient class to utilize the new parameter.
  3. Update any existing calls to these methods in other parts of the codebase.

You can use the following script to verify these changes:

This script will help ensure that all necessary updates have been made throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify updates to related classes and usage of new methods

# Check for updates in the interface
echo "Checking NamespaceOpenApiService interface:"
rg --type java "interface NamespaceOpenApiService" -A 10

# Check for updates in ApolloOpenApiClient
echo "Checking ApolloOpenApiClient class:"
rg --type java "class ApolloOpenApiClient" -A 20

# Check for existing calls to getNamespace and getNamespaces
echo "Checking existing calls to getNamespace and getNamespaces:"
rg --type java "getNamespace\(|getNamespaces\("

Length of output: 22305

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (4)

103-107: LGTM! Consider adding @Deprecated annotation.

The deprecation of the existing getNamespaces method is well-implemented. The comment correctly directs users to the new method, and the implementation ensures backward compatibility.

Consider adding the @Deprecated annotation to complement the Javadoc @deprecated tag:

+  @Deprecated
   @deprecated use {@link ApolloOpenApiClient#getNamespaces(String, String, String, boolean)} instead
   */
  public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
    return namespaceService.getNamespaces(appId, env, clusterName, true);
  }

109-114: LGTM! Consider enhancing the Javadoc.

The new getNamespaces method with the fillItemDetail parameter aligns well with the PR objectives. It provides the desired flexibility in retrieving namespace information.

Consider enhancing the Javadoc to explain the purpose of the fillItemDetail parameter:

   /**
    * Get the namespaces
+   * @param fillItemDetail if true, fill item details for each namespace; if false, only return namespace metadata
    * @since 2.4.0
    */
  public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName, boolean fillItemDetail) {
    return namespaceService.getNamespaces(appId, env, clusterName, fillItemDetail);
  }

136-140: LGTM! Consider adding @Deprecated annotation.

The deprecation of the existing getNamespace method is well-implemented. The comment correctly directs users to the new method, and the implementation ensures backward compatibility.

Consider adding the @Deprecated annotation to complement the Javadoc @deprecated tag:

+  @Deprecated
   @deprecated use {@link ApolloOpenApiClient#getNamespace(String, String, String, String, boolean)} instead
   */
  public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
    return namespaceService.getNamespace(appId, env, clusterName, namespaceName, true);
  }

142-147: LGTM! Consider enhancing the Javadoc.

The new getNamespace method with the fillItemDetail parameter aligns well with the PR objectives. It provides the desired flexibility in retrieving namespace information for a specific namespace.

Consider enhancing the Javadoc to explain the purpose of the fillItemDetail parameter:

   /**
    * Get the namespace
+   * @param fillItemDetail if true, fill item details for the namespace; if false, only return namespace metadata
    * @since 2.4.0
    */
  public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName, boolean fillItemDetail) {
    return namespaceService.getNamespace(appId, env, clusterName, namespaceName, fillItemDetail);
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6405daa and 2e0e46f.

📒 Files selected for processing (4)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/NamespaceOpenApiService.java (1 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (2 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/NamespaceOpenApiService.java (4 hunks)
  • apollo-openapi/src/test/java/com/ctrip/framework/apollo/openapi/client/service/NamespaceOpenApiServiceTest.java (4 hunks)
🧰 Additional context used
🔇 Additional comments (4)
apollo-openapi/src/test/java/com/ctrip/framework/apollo/openapi/client/service/NamespaceOpenApiServiceTest.java (3)

76-76: LGTM: Error handling test updated correctly.

The test method has been properly updated to use the new signature of getNamespace with the additional fillItemDetail parameter. This change maintains the integrity of the error handling test.


101-101: LGTM: Error handling test for getNamespaces updated correctly.

The test method has been properly updated to use the new signature of getNamespaces with the additional fillItemDetail parameter. This change maintains the integrity of the error handling test for the getNamespaces method.


Line range hint 1-160: Summary of changes and suggestions

The test file has been successfully updated to accommodate the new fillItemDetail parameter in the getNamespace and getNamespaces methods. The changes maintain existing test coverage and error handling scenarios. However, to ensure comprehensive testing, consider adding test cases for when fillItemDetail is set to false for both getNamespace and getNamespaces methods.

Overall, the changes align well with the PR objectives to support the new parameter for controlling whether to fill item details in namespace queries.

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (1)

Line range hint 103-147: Overall changes align well with PR objectives.

The modifications to ApolloOpenApiClient successfully implement the new fillItemDetail parameter for both getNamespaces and getNamespace methods. This aligns perfectly with the PR objective of allowing clients to specify whether to include item information when fetching Namespace data.

Key points:

  1. Backward compatibility is maintained through method overloading and appropriate deprecation.
  2. New methods are clearly documented with the version they were introduced (2.4.0).
  3. The implementation delegates to the namespaceService, which is expected to handle the new parameter.

These changes should effectively address the issue of resource-intensive retrieval of unnecessary item data, as described in the linked issue #5243.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant